package com.huanong.it.xwweibo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huanong.it.xwcommon.entity.Comment;
import com.huanong.it.xwcommon.service.CommentService;
import com.huanong.it.xwcommon.vo.Result;
import com.huanong.it.xwweibo.authority.common.utils.SecurityUtils;
import com.huanong.it.xwweibo.mapper.CommentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentMapper commentMapper;

    @Override
    public Result<Comment> addComment(int wbid, String content) {
        Comment comment = new Comment();
        comment.setWbId(wbid);
        comment.setUserLoginName(SecurityUtils.getCurrentUser().getUsername());
        comment.setContent(content);
        comment.setCreateTime(new Date());
        commentMapper.insert(comment);
        return new Result<Comment>(200,comment,"评论成功");
    }

    @Override
    public Result<Comment> delComment(int cmid) {
        commentMapper.deleteById(cmid);
        return new Result<Comment>(200,null,"删除成功");
    }

    @Override
    public Result<Comment> updateComment(int cmid, String content) {
        Comment comment = commentMapper.selectById(cmid);
        comment.setContent(content);
        commentMapper.updateById(comment);
        return new Result<Comment>(200,comment,"删除成功");
    }
}
